/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package newpackage;

import java.awt.Color;
import java.util.ArrayList;
import java.util.Map;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;

/**
 *
 * @author user
 */
public class Chart 
{
  public static JFreeChart createChart(String title,String x_axis,String y_axis,ArrayList<ChartData> chartData)
    {
     DefaultCategoryDataset bardataset = new DefaultCategoryDataset();  
     
for(ChartData cd:chartData)
{
     bardataset.setValue((Number)cd.getData(), cd.getColumn_key(), cd.getRow_key());
}
     
//     
//     bardataset.setValue(6,"Marks" ,"Aditi" );  
//     bardataset.setValue(3,"Marks" ,"Pooja" );  
//     bardataset.setValue(10,"Marks" ,"Ria" );  
//     bardataset.setValue(5,"Marks" ,"Twinkle" );  
//     bardataset.setValue(20,"Marks" ,"Rutvi" );  
    
     JFreeChart barchart = ChartFactory.createBarChart(  
         title,      //Title  
         x_axis,             // X-axis Label  
         y_axis,               // Y-axis Label  
         bardataset,             // Dataset  
         PlotOrientation.VERTICAL,      //Plot orientation  
         false,                // Show legend  
         true,                // Use tooltips  
         false                // Generate URLs  
      );  
     barchart.getTitle().setPaint(Color.BLUE);    // Set the colour of the title  
     barchart.setBackgroundPaint(Color.WHITE);    // Set the background colour of the chart  
     CategoryPlot cp = barchart.getCategoryPlot();  // Get the Plot object for a bar graph  
     cp.setBackgroundPaint(Color.WHITE);       // Set the plot background colour  
     cp.setRangeGridlinePaint(Color.RED);      // Set the colour of the plot gridlines  
  
    return barchart;
    }
    
}
